package com.linkage.jz.bankruptcy.activity.Vote;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.linkage.jz.bankruptcy.R;
import com.linkage.jz.bankruptcy.bean.Vote.ProVote;
import com.linkage.jz.bankruptcy.fragment.Vote.ProVoteGroupInfoFragment;
import com.linkage.jz.bankruptcy.utils.BundleUtils;

/**
 * 我的表决结果
 */
public class ProVoteMyVoteResultActivity extends ProVoteBaseActivity {

    private ProVote proVote;

    private String groupId;
    private int voteOpinion;
    private String supplementOpinion;
    private boolean allowChange;

    private ImageButton titleBack;
    private TextView titleText;
    private LinearLayout layoutVoteInfo;
    private TextView myVoteResult;
    private TextView myVoteOpinion;
    private TextView textAllowChange;
    private Button btnAllowChange;

    public static Intent start(Context context, String groupId, int voteOpinion, String supplementOpinion, boolean allowChange) {
        Intent intent = new Intent(context, ProVoteMyVoteResultActivity.class);
        intent.putExtra("groupId", groupId);
        intent.putExtra("voteOpinion", voteOpinion);
        intent.putExtra("supplementOpinion", supplementOpinion);
        intent.putExtra("allowChange", allowChange);
        return intent;
    }

    @Override
    public void initView() {
        setContentView(R.layout.activity_pro_vote_my_vote_result);
        layoutVoteInfo = findViewById(R.id.layout_vote_info);
        myVoteResult = findViewById(R.id.my_vote_result);
        myVoteOpinion = findViewById(R.id.my_vote_desc);
        textAllowChange = findViewById(R.id.txt_operate_change);
        btnAllowChange = findViewById(R.id.btn_operate_change);
    }

    @Override
    public void initTitle() {
        titleBack = findViewById(R.id.title_back);
        titleText = findViewById(R.id.title_text);
        titleBack.setOnClickListener(this);
        titleText.setText("我的表决");
    }

    @Override
    public void initData() {
        proVote = BundleUtils.getProVote();
        groupId = getIntent().getStringExtra("groupId");
        voteOpinion = getIntent().getIntExtra("voteOpinion", 0);
        supplementOpinion = getIntent().getStringExtra("supplementOpinion");
        allowChange = getIntent().getBooleanExtra("allowChange", false);
        myVoteResult.setText(voteOpinion == 0 ? "不同意" : "同意");
        myVoteOpinion.setText(TextUtils.isEmpty(supplementOpinion) ? "无表决意见" : supplementOpinion);
        if(proVote.getStatus() == 2) {
            if(allowChange) {
                textAllowChange.setVisibility(View.GONE);
                btnAllowChange.setVisibility(View.VISIBLE);
            }else {
                textAllowChange.setVisibility(View.VISIBLE);
                btnAllowChange.setVisibility(View.GONE);
            }
        }else {
            textAllowChange.setVisibility(View.GONE);
            btnAllowChange.setVisibility(View.GONE);
        }
        btnAllowChange.setOnClickListener(this);
    }

    @Override
    public void setListener() {
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.title_back:
                finish();
                break;
            case R.id.btn_operate_change:
                Intent intent = new Intent(this, ProVoteEditVoteActivity.class);
                intent.putExtra("vote", false);
                intent.putExtra("voteId", proVote.getId());
                if(!TextUtils.isEmpty(groupId)) {
                    intent.putExtra("groupId", groupId);
                }
                startActivityForResult(intent, ProVoteEditVoteActivity.REQUEST_CODE_VOTE);
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
    }
}
